﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ChiakiYu.Core.Domain.Entities;
using ChiakiYu.Model.Roles;

namespace ChiakiYu.Model.Permissions
{
    /// <summary>
    ///     权限
    /// </summary>
    public class Permission : Entity<string>
    {
        public Permission()
        {
            Id = Guid.NewGuid().ToString("N");
        }

        [StringLength(32)]
        public override string Id { get; set; }

        /// <summary>
        ///     控制器名
        /// </summary>
        public string Controller { get; set; }


        /// <summary>
        ///     控制器描述
        /// </summary>
        [StringLength(100)]
        public string ControllerDescription { get; set; }

        /// <summary>
        ///     方法名
        /// </summary>
        public string Action { get; set; }

        /// <summary>
        ///     方法描述
        /// </summary>
        [StringLength(100)]
        public string ActionDescription { get; set; }

        /// <summary>
        ///     方法参数字符串
        /// </summary>
        public string Params { get; set; }

    }




    public class PermissionEqualityComparer : IEqualityComparer<Permission>
    {
        public bool Equals(Permission x, Permission y)
        {
            //比较Controller,Action
            return x.Controller == y.Controller && x.Action == y.Action;
        }

        public int GetHashCode(Permission obj)
        {
            var str = string.Format("{0}-{1}", obj.Controller, obj.Action);
            return str.GetHashCode();
        }
    }

}